package com.tenentia.pcmps.swm.business.implementation;

import java.util.List;

import org.apache.log4j.Logger;

import com.tenentia.pcmps.swm.Constants;
import com.tenentia.pcmps.swm.business.BusinessLogicException;
import com.tenentia.pcmps.swm.business.interfaces.StatesManager;
import com.tenentia.pcmps.swm.data.DataAccessObjectsFactory;
import com.tenentia.pcmps.swm.data.beans.State;
import com.tenentia.pcmps.swm.data.interfaces.StatesDAO;

/**
 * 
 * @author tEnEntia, S.L.N.E.
 * 
 */
public class StatesManagerImpl implements StatesManager {

	private static final Logger LOGGER = Logger.getLogger(StatesManagerImpl.class.getPackage().getName());

	StatesManagerImpl() {

		super();
	}
	
	@Override
	public State get(State state) throws BusinessLogicException {
		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			StatesDAO dataAccessObject = (StatesDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.STATES_DAO);
			return dataAccessObject.get(state);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}

	}

	@Override
	public List<State> getAvailableStates() throws BusinessLogicException {
		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);

		try {
			StatesDAO dataAccessObject = (StatesDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.STATES_DAO);
			return dataAccessObject.getAvailableStates();
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}

	}

}
